const koa   = require('koa'),
      error = require('koa-json-error');

const app = koa();

/**
 * error(opts)
 *   opts:
 *     format: 自定义返回数据
 */
app.use(error({
    format: function (err) {
        return {
            status : 200,
            code   : -1,
            message: err.message || 'OK'
        };
    }
}));

app.use(function *() {
    if(this.path === '/error')
        this.throw('error');
    this.body = 'Try Get /error'
});

app.listen(3000);